import com.demo.component.*;
import com.demo.controller.StudentController;
import com.demo.controller.UserAdviceController;
import com.demo.controller.UserController;
import com.demo.model.Student;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

import java.beans.Introspector;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Locale;
import java.util.Map;

/**
 * @program: spring-demo2
 * @author: JCM
 * @create: 2023-02-21 08:52
 * @description:
 **/
public class App {
    public static void main(String[] args) {
        //1. 先得到 Spring 对象
        ApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");

        System.out.println("context   成功");
        // 2. 从 Spring 中取出 bean 对象
        // 根据 bean 的 id 获取 bean对象
        //User user = (User) context.getBean("user");
        //根据 bean 类型来获取 bean
        //User user1 = context.getBean(User.class);
        // 根据 bean 名称加上 bean 类型获取 bean对象
        //User user2 = context.getBean("user",User.class);
//        //3. 使用 bean（可选）
//        System.out.println(user.sayHi());

//        ArticleController articleController = context.getBean("articleController",ArticleController.class);
//        System.out.println(articleController.sayHello());

//        aController controller = context.getBean("aController",aController.class);
//        System.out.println(controller.sayHi());

//        BController controller = context.getBean("BController",BController.class);
//        System.out.println(controller.sayHi());

//        String s1 = "UserInfo";
//        System.out.println("s1: " + Introspector.decapitalize(s1));
//
//        String s2 = "userInfo";
//        System.out.println("s2: " + Introspector.decapitalize(s2));
//
//        String s3 = "UInfo";
//        System.out.println("s3: " + Introspector.decapitalize(s3));

//        UserComponent component = context.getBean("userComponent",UserComponent.class);
//        System.out.println(component.sayHi());

//        User user = context.getBean("user",User.class);
//        System.out.println(user.sayHi());

//        Student student = context.getBean("s1",Student.class);
//        System.out.println(student.toString());

//        StudentController sc = context.getBean("studentController",StudentController.class);
//        sc.sayHi();

        // 李四
        UserController uc = context.getBean("userController",UserController.class);
        uc.getUser();

        // 王五
        UserAdviceController uac = context.getBean("userAdviceController",UserAdviceController.class);
        uac.getUser();

    }
}
